package org.ldx.lotterysystem.dao.mapper;

import org.apache.ibatis.annotations.*;
import org.ldx.lotterysystem.dao.dataobject.ActivityUserDo;

import java.util.List;

@Mapper
public interface ActivityUserMapper {
    @Insert("<script>" +
            " insert into activity_user (activity_id, user_id, user_name, status)" +
            " values <foreach collection = 'items' item='item' index='index' separator=','>" +
            " (#{item.activityId}, #{item.userId}, #{item.userName}, #{item.status})" +
            " </foreach>" +
            " </script>")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    int batchInsert(@Param("items") List<ActivityUserDo> activityUserDOList);

    @Select("select * from activity_user where activity_id = #{activityId}")
    List<ActivityUserDo> selectByActivityId(@Param("activityId") Long activityId);

    /**
     * 根据活动和人员id列表查询人员信息列表
     * @param activityId
     * @param userIds
     * @return
     */
    @Select("<script>" +
            "select * from activity_user where activity_id = #{activityId} and user_id in" +
            " <foreach collection = 'userIds' item = 'userId' open = '(' separator=',' close = ')'>" +
            " #{userId}" +
            " </foreach>" +
            "</script>")
    List<ActivityUserDo> batchSelectByAUIds(Long activityId, List<Long> userIds);

    /**
     * 按批次修改活动关联的人员状态
     * @param activityId
     * @param userIds
     * @param name
     */
    @Update("<script>" +
            "update activity_user set status = #{name} " +
            "where activity_id = #{activityId} and user_id in" +
            " <foreach collection = 'userIds' item = 'userId' open = '(' separator=',' close = ')'>" +
            " #{userId}" +
            " </foreach>" +
            "</script>")
    void batchUpdateStatus(Long activityId, List<Long> userIds, String name);
}
